const fs = require("fs");
const puppeteer = require("puppeteer");

async function savePageHtml(link, outputFile) {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(link, { waitUntil: "networkidle2" });

  const html = await page.evaluate(() => document.documentElement.outerHTML);

  // 保存到文件
  fs.writeFileSync(outputFile, html);

  console.log(`HTML 页面已保存到 ${outputFile}`);
  await browser.close();

  return html;
}

// 调用函数
const link = "https://www.hbgyl.com.cn/#/index";
const outputFile = "output.html";
console.log(savePageHtml(link, outputFile));

// module.exports = savePageHtml;
